//
//  RegistViewController.swift
//  guoziyuan
//
//  Created by aibaimm on 2017/8/22.
//  Copyright © 2017年 guoziyuan. All rights reserved.
//

import UIKit

class RegistViewController: BaseSubViewController {
    @IBOutlet weak var secrectButton: UIButton!
    @IBOutlet weak var lineUp:UILabel!
    @IBOutlet weak var lineDown:UILabel!
    
    @IBOutlet weak var password:UITextField!
    @IBOutlet weak var username:UITextField!
    override func viewDidLoad() {
        super.viewDidLoad()
        edgesForExtendedLayout = [] //去掉偏移的视图效果 iOS7及以后的版本支持，self.view.frame.origin.y会下移64像素至navigationBar下方。

        // Do any additional setup after loading the view.
        
        
        lineUp.frame.size.height = LINEHEIGHT
        lineDown.frame.size.height = LINEHEIGHT
        lineUp.backgroundColor = lightColor
        lineDown.backgroundColor = lightColor

        
        
   
        
        
        
        
        let _btns = LoadButton(frame: CGRect(x: 60, y: 400-64, width: SCREENWIDTH - 120, height: 40.0))
        _btns.setLayerCornerRadius(20, withWidth: 0, color: nil)
        _btns.setBackgroundImage(UIImage(named: "loginback"), for: .normal)
        _btns.setTitle("注册", for: .normal)
        _btns.titleLabel?.font = fontSize(size: 14)
        _btns.setTitleColor(UIColor.white, for: .normal)
        _btns.addTarget(self, action: #selector(buttonClick(registAnimal:)), for: .touchUpInside)
        view.addSubview(_btns)
        
        
        
        
        
    }
    func buttonClick(registAnimal:LoadButton) {
        
        
        if username.text! == "" {
            self.view.makeToast(message: "请输入手机号")
            return
        }
        
        
        if password.text! == "" {
            self.view.makeToast(message: "请输入密码")
            return
        }
       registAnimal.toggle()
        
        ///POST 请求
        XMSessionManager.shared.request(Method: XMHTTPMethod.POST,URLString: "http://www.guoziyuan.shop/api/member/apiRegister", parameters: ["mobile":"17502163719" as AnyObject,"password":"88888888" as AnyObject,"nickname":"17502163719" as AnyObject], completed:{(json: AnyObject?,isSuccess: Bool)-> () in
            
            // 请求成功
            if isSuccess {
                print(json ?? "===")
            } else {
                print("请求失败")
            }
        })
        
        
        
       
    }
    
    
    @IBAction func lookOrClose(){
        if password.isSecureTextEntry {
            password.isSecureTextEntry = false
            secrectButton.setImage(UIImage(named:"new-show"), for: UIControlState.normal)
        }else{
            password.isSecureTextEntry = true
            secrectButton.setImage(UIImage(named:"new-hide"), for: UIControlState.normal)
        }
    }
    
    override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
        password.resignFirstResponder()
        username.resignFirstResponder()
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
